import path, { dirname } from "path";
import { fileURLToPath } from "url";
import { merge } from "webpack-merge";
import webpackNodeExternals from "webpack-node-externals";
import base from "./webpack.base.js";
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);

const serverConfig = {
  entry: "./src/server",
  output: {
    filename: "bundle.cjs",
    publicPath: '/'
  },
  target: "node",
  externals: [webpackNodeExternals()],
    module:{
      rules: [
        {
          test: /\.css$/,
          use: [ "isomorphic-style-loader", "css-loader?modules"]
        },
        {
          test: /\.(jpg)|(png)|(gif)$/,
          use: [{
            loader: "file-loader",
            options: {
              name: "img/[name].[hash:5].[ext]",
              emitFile: false
            }
          }]
        }
      ]
    }
};

export default merge(base, serverConfig);
